package com.tcxhb.job.agent.processor;

import com.tcxhb.job.agent.processor.impl.ShellProcessor;
import com.tcxhb.job.agent.processor.impl.SpringBeanProcessor;
import com.tcxhb.job.common.constants.JobTypeConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Auther: tcxhb
 * @Date: 2023/11/5
 */
@Component
public class JobProcessorFactory {
    @Autowired
    private SpringBeanProcessor springBeanProcessor;
    @Autowired
    private ShellProcessor shellProcessor;

    private Map<String, JobProcessor> processorMap = new HashMap<>();

    @PostConstruct
    public void init() {
        processorMap.put(JobTypeConstants.JAVA_BEAN, springBeanProcessor);
        processorMap.put(JobTypeConstants.SHELL, shellProcessor);
    }

    public JobProcessor getHandle(String jobType) {
        return processorMap.get(jobType);
    }
}
